package chances.epg.navigator.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import chances.epg.commons.utils.PathUtils;
import chances.epg.config.EpgSiteContext;
import chances.epg.navigator.context.AccessContext;


@Controller
public class IndexAccessController extends AccessController {
	
	@Value("${remove.session.before.entry.index:false}")
	private boolean removeSession ;
	/**
	 * 站点入口.
	 * @param model
	 * @param request
	 * @return
	 * @throws IOException 
	 */
	@RequestMapping(value = "/{siteCode}/index")
	public String index(ModelMap model, HttpServletRequest request,HttpServletResponse response) throws IOException {
		
		AccessContext context = accessContextFactory.createAccessContext(request);
		String code = context.getSiteCode();
		
		EpgSiteContext epgSiteContext = EpgSiteContext.get(request.getServletContext(),code);
		String defautPath = PathUtils.join(navigateUrlFactory.generateBizURL(context, epgSiteContext.getDefaultBizCode()));
			
    		
		response.sendRedirect(defautPath);
		return null;
	}
	

}
